        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>ConstantVolumeJoint class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="ConstantVolumeJoint">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/ConstantVolumeJoint.html">ConstantVolumeJoint</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>ConstantVolumeJoint</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class ConstantVolumeJoint extends Joint {
 List&lt;Body&gt; bodies;
 List&lt;num&gt; targetLengths;
 num targetVolume;

 List&lt;vec2&gt; normals;

 TimeStep step;

 num _impulse;

 World _world;

 List&lt;DistanceJoint&gt; distanceJoints;

 num frequencyHz;
 num dampingRatio;

 ConstantVolumeJoint(this._world, ConstantVolumeJointDef def) :
   super(def),
   _impulse = 0 {
   if (def.bodies.length &lt;= 2) {
     throw new ArgumentError(
         "You cannot create a constant volume joint with less than three "
         "bodies.");
   }

   // Create a fixed size array with a capacity equal to the number of elements
   // in the growable array in the definition.
   bodies = new List.from(def.bodies);

   targetLengths = new List&lt;num&gt;(bodies.length);
   for (int i = 0; i &lt; targetLengths.length; ++i) {
     final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
     vec2 temp = new vec2.copy(bodies[i].worldCenter);
     temp.sub(bodies[next].worldCenter);
     num dist = temp.length;
     targetLengths[i] = dist;
   }
   targetVolume = area;

   if (def.joints != null &amp;&amp; def.joints.length != def.bodies.length) {
     throw new ArgumentError(
         "Incorrect joint definition.  Joints have to correspond to "
         "the bodies");
   }

   if (def.joints == null) {
     final djd = new DistanceJointDef();
     distanceJoints = new List&lt;DistanceJoint&gt;(bodies.length);
     for (int i = 0; i &lt; targetLengths.length; ++i) {
       final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
       djd.frequencyHz = def.frequencyHz;
       djd.dampingRatio = def.dampingRatio;
       djd.initialize(bodies[i], bodies[next], bodies[i].worldCenter,
           bodies[next].worldCenter);
       distanceJoints[i] = _world.createJoint(djd);
     }
   } else {
     distanceJoints = new List&lt;DistanceJoint&gt;(def.joints.length);
     distanceJoints.setRange(0, def.joints.length, def.joints);
   }

   frequencyHz = def.frequencyHz;
   dampingRatio = def.dampingRatio;

   normals = new List&lt;vec2&gt;(bodies.length);
   for (int i = 0; i &lt; normals.length; ++i) {
     normals[i] = new vec2.zero();
   }

   this.bodyA = bodies[0];
   this.bodyB = bodies[1];
   this.collideConnected = false;
 }

 void inflate(num factor) {
   targetVolume *= factor;
 }

 void destructor() {
   for (int i = 0; i &lt; distanceJoints.length; ++i) {
     _world.destroyJoint(distanceJoints[i]);
   }
 }

 num get area {
   num result = 0.0;
   result += bodies[bodies.length - 1].worldCenter.x * bodies[0].worldCenter.y
       - bodies[0].worldCenter.x * bodies[bodies.length - 1].worldCenter.y;
   for (int i = 0; i &lt; bodies.length - 1; ++i) {
     result += bodies[i].worldCenter.x * bodies[i + 1].worldCenter.y
         - bodies[i + 1].worldCenter.x * bodies[i].worldCenter.y;
   }
   result *= .5;
   return result;
 }

 /** Apply the position correction to the particles. */
 bool constrainEdges(TimeStep argStep) {
   num perimeter = 0.0;
   for (int i = 0; i &lt; bodies.length; ++i) {
     final int next = (i == bodies.length - 1) ? 0 : i + 1;
     num dx = bodies[next].worldCenter.x - bodies[i].worldCenter.x;
     num dy = bodies[next].worldCenter.y - bodies[i].worldCenter.y;
     num dist = math.sqrt(dx * dx + dy * dy);
     if (dist &lt; Settings.EPSILON) {
       dist = 1.0;
     }
     normals[i].x = dy / dist;
     normals[i].y = -dx / dist;
     perimeter += dist;
   }

   final delta = new vec2.zero();

   num deltaArea = targetVolume - area;
   num toExtrude = 0.5 * deltaArea / perimeter; // relaxationFactor
   bool done = true;
   for (int i = 0; i &lt; bodies.length; ++i) {
     final int next = (i == bodies.length - 1) ? 0 : i + 1;
     delta.copyFrom(normals[i]).add(normals[next]).scale(toExtrude);
     num norm = delta.length;
     if (norm &gt; Settings.MAX_LINEAR_CORRECTION) {
       delta.scale(Settings.MAX_LINEAR_CORRECTION / norm);
     }
     if (norm &gt; Settings.LINEAR_SLOP) {
       done = false;
     }
     bodies[next].sweep.center.add(delta);
     bodies[next].synchronizeTransform();
   }

   return done;
 }

 void initVelocityConstraints(TimeStep argStep) {
   step = argStep;

   final d = new List&lt;vec2&gt;(bodies.length);
   for (int i = 0; i &lt; bodies.length; i++) {
     d[i] = new vec2.zero();
   }

   for (int i = 0; i &lt; bodies.length; ++i) {
     final int prev = (i == 0) ? bodies.length - 1 : i - 1;
     final int next = (i == bodies.length - 1) ? 0 : i + 1;
     d[i].copyFrom(bodies[next].worldCenter);
     d[i].sub(bodies[prev].worldCenter);
   }

   if (step.warmStarting) {
     _impulse *= step.dtRatio;
     for (int i = 0; i &lt; bodies.length; ++i) {
       bodies[i].linearVelocity.x += bodies[i].invMass * d[i].y *
           .5 * _impulse;
       bodies[i].linearVelocity.y += bodies[i].invMass * -d[i].x *
           .5 * _impulse;
     }
   } else {
     _impulse = 0.0;
   }
 }

 /**
  * Solves for the impact of this joint on the positions of the connected
  * bodies. Implements abstract method in [Joint].
  */
 bool solvePositionConstraints(num baumgarte) {
   return constrainEdges(step);
 }

 /**
  * Solves for the impact of this joint on the velocities of the connected
  * bodies. Implements abstract method in [Joint].
  */
 void solveVelocityConstraints(TimeStep argStep) {
   num crossMassSum = 0.0;
   num dotMassSum = 0.0;

   final d = new List&lt;vec2&gt;(bodies.length);
   for (int i = 0; i &lt; bodies.length; i++) {
     d[i] = new vec2.zero();
   }

   for (int i = 0; i &lt; bodies.length; ++i) {
     final int prev = (i == 0) ? bodies.length - 1 : i - 1;
     final int next = (i == bodies.length - 1) ? 0 : i + 1;
     d[i].copyFrom(bodies[next].worldCenter);
     d[i].sub(bodies[prev].worldCenter);
     dotMassSum += d[i].length2 / bodies[i].mass;
     crossMassSum += cross(bodies[i].linearVelocity, d[i]);
   }
   num lambda = -2.0 * crossMassSum / dotMassSum;
   _impulse += lambda;
   for (int i = 0; i &lt; bodies.length; ++i) {
     bodies[i].linearVelocity.x += bodies[i].invMass * d[i].y * .5 * lambda;
     bodies[i].linearVelocity.y += bodies[i].invMass * -d[i].x * .5 * lambda;
   }
 }

 void getAnchorA(vec2 argOut) { throw new UnimplementedError(); }

 void getAnchorB(vec2 argOut) { throw new UnimplementedError(); }

 void getReactionForce(num inv_dt, vec2 argOut) { throw new UnimplementedError(); }

 num getReactionTorque(num inv_dt) { throw new UnimplementedError(); }
}
</pre>
</div>
<h3>Extends</h3>
<p>
<span class="type-box"><span class="icon-class"></span><a href="../box2d/Joint.html">Joint</a></span>&nbsp;&gt;&nbsp;<span class="type-box"><span class="icon-class"></span><strong>ConstantVolumeJoint</strong></span></p>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="ConstantVolumeJoint">
<button class="show-code">Code</button>
new <strong>ConstantVolumeJoint</strong>(<a href="../box2d/World.html">World</a> _world, <a href="../box2d/ConstantVolumeJointDef.html">ConstantVolumeJointDef</a> def) <a class="anchor-link" href="#ConstantVolumeJoint"
              title="Permalink to ConstantVolumeJoint.ConstantVolumeJoint">#</a></h4>
<div class="doc">
<pre class="source">
ConstantVolumeJoint(this._world, ConstantVolumeJointDef def) :
 super(def),
 _impulse = 0 {
 if (def.bodies.length &lt;= 2) {
   throw new ArgumentError(
       "You cannot create a constant volume joint with less than three "
       "bodies.");
 }

 // Create a fixed size array with a capacity equal to the number of elements
 // in the growable array in the definition.
 bodies = new List.from(def.bodies);

 targetLengths = new List&lt;num&gt;(bodies.length);
 for (int i = 0; i &lt; targetLengths.length; ++i) {
   final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
   vec2 temp = new vec2.copy(bodies[i].worldCenter);
   temp.sub(bodies[next].worldCenter);
   num dist = temp.length;
   targetLengths[i] = dist;
 }
 targetVolume = area;

 if (def.joints != null &amp;&amp; def.joints.length != def.bodies.length) {
   throw new ArgumentError(
       "Incorrect joint definition.  Joints have to correspond to "
       "the bodies");
 }

 if (def.joints == null) {
   final djd = new DistanceJointDef();
   distanceJoints = new List&lt;DistanceJoint&gt;(bodies.length);
   for (int i = 0; i &lt; targetLengths.length; ++i) {
     final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
     djd.frequencyHz = def.frequencyHz;
     djd.dampingRatio = def.dampingRatio;
     djd.initialize(bodies[i], bodies[next], bodies[i].worldCenter,
         bodies[next].worldCenter);
     distanceJoints[i] = _world.createJoint(djd);
   }
 } else {
   distanceJoints = new List&lt;DistanceJoint&gt;(def.joints.length);
   distanceJoints.setRange(0, def.joints.length, def.joints);
 }

 frequencyHz = def.frequencyHz;
 dampingRatio = def.dampingRatio;

 normals = new List&lt;vec2&gt;(bodies.length);
 for (int i = 0; i &lt; normals.length; ++i) {
   normals[i] = new vec2.zero();
 }

 this.bodyA = bodies[0];
 this.bodyB = bodies[1];
 this.collideConnected = false;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field inherited"><h4 id="active">
<button class="show-code">Code</button>
final bool         <strong>active</strong> <a class="anchor-link"
            href="#active"
            title="Permalink to ConstantVolumeJoint.active">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Short-cut function to determine if either body is inactive. </p>
<pre class="source">
bool get active =&gt; bodyA.active &amp;&amp; bodyB.active;
</pre>
</div>
</div>
<div class="field"><h4 id="area">
<button class="show-code">Code</button>
final num         <strong>area</strong> <a class="anchor-link"
            href="#area"
            title="Permalink to ConstantVolumeJoint.area">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get area {
 num result = 0.0;
 result += bodies[bodies.length - 1].worldCenter.x * bodies[0].worldCenter.y
     - bodies[0].worldCenter.x * bodies[bodies.length - 1].worldCenter.y;
 for (int i = 0; i &lt; bodies.length - 1; ++i) {
   result += bodies[i].worldCenter.x * bodies[i + 1].worldCenter.y
       - bodies[i + 1].worldCenter.x * bodies[i].worldCenter.y;
 }
 result *= .5;
 return result;
}
</pre>
</div>
</div>
<div class="field"><h4 id="bodies">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/Body.html">Body</a>&gt;         <strong>bodies</strong> <a class="anchor-link"
            href="#bodies"
            title="Permalink to ConstantVolumeJoint.bodies">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bodies
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyA">
<button class="show-code">Code</button>
<a href="../box2d/Body.html">Body</a>         <strong>bodyA</strong> <a class="anchor-link"
            href="#bodyA"
            title="Permalink to ConstantVolumeJoint.bodyA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bodyA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyB">
<button class="show-code">Code</button>
<a href="../box2d/Body.html">Body</a>         <strong>bodyB</strong> <a class="anchor-link"
            href="#bodyB"
            title="Permalink to ConstantVolumeJoint.bodyB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bodyB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="collideConnected">
<button class="show-code">Code</button>
bool         <strong>collideConnected</strong> <a class="anchor-link"
            href="#collideConnected"
            title="Permalink to ConstantVolumeJoint.collideConnected">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
collideConnected
</pre>
</div>
</div>
<div class="field"><h4 id="dampingRatio">
<button class="show-code">Code</button>
num         <strong>dampingRatio</strong> <a class="anchor-link"
            href="#dampingRatio"
            title="Permalink to ConstantVolumeJoint.dampingRatio">#</a>
        </h4>
        <div class="doc">
<pre class="source">
dampingRatio
</pre>
</div>
</div>
<div class="field"><h4 id="distanceJoints">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/DistanceJoint.html">DistanceJoint</a>&gt;         <strong>distanceJoints</strong> <a class="anchor-link"
            href="#distanceJoints"
            title="Permalink to ConstantVolumeJoint.distanceJoints">#</a>
        </h4>
        <div class="doc">
<pre class="source">
distanceJoints
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeA">
<button class="show-code">Code</button>
<a href="../box2d/JointEdge.html">JointEdge</a>         <strong>edgeA</strong> <a class="anchor-link"
            href="#edgeA"
            title="Permalink to ConstantVolumeJoint.edgeA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
edgeA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeB">
<button class="show-code">Code</button>
<a href="../box2d/JointEdge.html">JointEdge</a>         <strong>edgeB</strong> <a class="anchor-link"
            href="#edgeB"
            title="Permalink to ConstantVolumeJoint.edgeB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
edgeB
</pre>
</div>
</div>
<div class="field"><h4 id="frequencyHz">
<button class="show-code">Code</button>
num         <strong>frequencyHz</strong> <a class="anchor-link"
            href="#frequencyHz"
            title="Permalink to ConstantVolumeJoint.frequencyHz">#</a>
        </h4>
        <div class="doc">
<pre class="source">
frequencyHz
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIA">
<button class="show-code">Code</button>
num         <strong>invIA</strong> <a class="anchor-link"
            href="#invIA"
            title="Permalink to ConstantVolumeJoint.invIA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invIA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIB">
<button class="show-code">Code</button>
num         <strong>invIB</strong> <a class="anchor-link"
            href="#invIB"
            title="Permalink to ConstantVolumeJoint.invIB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invIB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassA">
<button class="show-code">Code</button>
num         <strong>invMassA</strong> <a class="anchor-link"
            href="#invMassA"
            title="Permalink to ConstantVolumeJoint.invMassA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invMassA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassB">
<button class="show-code">Code</button>
num         <strong>invMassB</strong> <a class="anchor-link"
            href="#invMassB"
            title="Permalink to ConstantVolumeJoint.invMassB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invMassB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="islandFlag">
<button class="show-code">Code</button>
bool         <strong>islandFlag</strong> <a class="anchor-link"
            href="#islandFlag"
            title="Permalink to ConstantVolumeJoint.islandFlag">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
islandFlag
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterA">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenterA</strong> <a class="anchor-link"
            href="#localCenterA"
            title="Permalink to ConstantVolumeJoint.localCenterA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
localCenterA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterB">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenterB</strong> <a class="anchor-link"
            href="#localCenterB"
            title="Permalink to ConstantVolumeJoint.localCenterB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
localCenterB
</pre>
</div>
</div>
<div class="field"><h4 id="normals">
<button class="show-code">Code</button>
List&lt;<a href="../vector_math/vec2.html">vec2</a>&gt;         <strong>normals</strong> <a class="anchor-link"
            href="#normals"
            title="Permalink to ConstantVolumeJoint.normals">#</a>
        </h4>
        <div class="doc">
<pre class="source">
normals
</pre>
</div>
</div>
<div class="field"><h4 id="step">
<button class="show-code">Code</button>
<a href="../box2d/TimeStep.html">TimeStep</a>         <strong>step</strong> <a class="anchor-link"
            href="#step"
            title="Permalink to ConstantVolumeJoint.step">#</a>
        </h4>
        <div class="doc">
<pre class="source">
step
</pre>
</div>
</div>
<div class="field"><h4 id="targetLengths">
<button class="show-code">Code</button>
List&lt;num&gt;         <strong>targetLengths</strong> <a class="anchor-link"
            href="#targetLengths"
            title="Permalink to ConstantVolumeJoint.targetLengths">#</a>
        </h4>
        <div class="doc">
<pre class="source">
targetLengths
</pre>
</div>
</div>
<div class="field"><h4 id="targetVolume">
<button class="show-code">Code</button>
num         <strong>targetVolume</strong> <a class="anchor-link"
            href="#targetVolume"
            title="Permalink to ConstantVolumeJoint.targetVolume">#</a>
        </h4>
        <div class="doc">
<pre class="source">
targetVolume
</pre>
</div>
</div>
<div class="field inherited"><h4 id="type">
<button class="show-code">Code</button>
int         <strong>type</strong> <a class="anchor-link"
            href="#type"
            title="Permalink to ConstantVolumeJoint.type">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
type
</pre>
</div>
</div>
<div class="field inherited"><h4 id="userData">
<button class="show-code">Code</button>
Object         <strong>userData</strong> <a class="anchor-link"
            href="#userData"
            title="Permalink to ConstantVolumeJoint.userData">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
userData
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="constrainEdges">
<button class="show-code">Code</button>
bool <strong>constrainEdges</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> argStep) <a class="anchor-link" href="#constrainEdges"
              title="Permalink to ConstantVolumeJoint.constrainEdges">#</a></h4>
<div class="doc">
<p>Apply the position correction to the particles. </p>
<pre class="source">
bool constrainEdges(TimeStep argStep) {
 num perimeter = 0.0;
 for (int i = 0; i &lt; bodies.length; ++i) {
   final int next = (i == bodies.length - 1) ? 0 : i + 1;
   num dx = bodies[next].worldCenter.x - bodies[i].worldCenter.x;
   num dy = bodies[next].worldCenter.y - bodies[i].worldCenter.y;
   num dist = math.sqrt(dx * dx + dy * dy);
   if (dist &lt; Settings.EPSILON) {
     dist = 1.0;
   }
   normals[i].x = dy / dist;
   normals[i].y = -dx / dist;
   perimeter += dist;
 }

 final delta = new vec2.zero();

 num deltaArea = targetVolume - area;
 num toExtrude = 0.5 * deltaArea / perimeter; // relaxationFactor
 bool done = true;
 for (int i = 0; i &lt; bodies.length; ++i) {
   final int next = (i == bodies.length - 1) ? 0 : i + 1;
   delta.copyFrom(normals[i]).add(normals[next]).scale(toExtrude);
   num norm = delta.length;
   if (norm &gt; Settings.MAX_LINEAR_CORRECTION) {
     delta.scale(Settings.MAX_LINEAR_CORRECTION / norm);
   }
   if (norm &gt; Settings.LINEAR_SLOP) {
     done = false;
   }
   bodies[next].sweep.center.add(delta);
   bodies[next].synchronizeTransform();
 }

 return done;
}
</pre>
</div>
</div>
<div class="method"><h4 id="destructor">
<button class="show-code">Code</button>
void <strong>destructor</strong>() <a class="anchor-link" href="#destructor"
              title="Permalink to ConstantVolumeJoint.destructor">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Override to handle destruction of joint. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void destructor() {
 for (int i = 0; i &lt; distanceJoints.length; ++i) {
   _world.destroyJoint(distanceJoints[i]);
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getAnchorA">
<button class="show-code">Code</button>
void <strong>getAnchorA</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getAnchorA"
              title="Permalink to ConstantVolumeJoint.getAnchorA">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the anchor point on bodyA in world coordinates. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getAnchorA(vec2 argOut) { throw new UnimplementedError(); }
</pre>
</div>
</div>
<div class="method"><h4 id="getAnchorB">
<button class="show-code">Code</button>
void <strong>getAnchorB</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getAnchorB"
              title="Permalink to ConstantVolumeJoint.getAnchorB">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the anchor point on bodyB in world coordinates. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getAnchorB(vec2 argOut) { throw new UnimplementedError(); }
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionForce">
<button class="show-code">Code</button>
void <strong>getReactionForce</strong>(num inv_dt, <a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getReactionForce"
              title="Permalink to ConstantVolumeJoint.getReactionForce">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction force on body2 at the joint anchor in Newtons. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getReactionForce(num inv_dt, vec2 argOut) { throw new UnimplementedError(); }
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionTorque">
<button class="show-code">Code</button>
num <strong>getReactionTorque</strong>(num inv_dt) <a class="anchor-link" href="#getReactionTorque"
              title="Permalink to ConstantVolumeJoint.getReactionTorque">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction torque on body2 in N*m. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
num getReactionTorque(num inv_dt) { throw new UnimplementedError(); }
</pre>
</div>
</div>
<div class="method"><h4 id="inflate">
<button class="show-code">Code</button>
void <strong>inflate</strong>(num factor) <a class="anchor-link" href="#inflate"
              title="Permalink to ConstantVolumeJoint.inflate">#</a></h4>
<div class="doc">
<pre class="source">
void inflate(num factor) {
 targetVolume *= factor;
}
</pre>
</div>
</div>
<div class="method"><h4 id="initVelocityConstraints">
<button class="show-code">Code</button>
void <strong>initVelocityConstraints</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> argStep) <a class="anchor-link" href="#initVelocityConstraints"
              title="Permalink to ConstantVolumeJoint.initVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void initVelocityConstraints(TimeStep argStep) {
 step = argStep;

 final d = new List&lt;vec2&gt;(bodies.length);
 for (int i = 0; i &lt; bodies.length; i++) {
   d[i] = new vec2.zero();
 }

 for (int i = 0; i &lt; bodies.length; ++i) {
   final int prev = (i == 0) ? bodies.length - 1 : i - 1;
   final int next = (i == bodies.length - 1) ? 0 : i + 1;
   d[i].copyFrom(bodies[next].worldCenter);
   d[i].sub(bodies[prev].worldCenter);
 }

 if (step.warmStarting) {
   _impulse *= step.dtRatio;
   for (int i = 0; i &lt; bodies.length; ++i) {
     bodies[i].linearVelocity.x += bodies[i].invMass * d[i].y *
         .5 * _impulse;
     bodies[i].linearVelocity.y += bodies[i].invMass * -d[i].x *
         .5 * _impulse;
   }
 } else {
   _impulse = 0.0;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="solvePositionConstraints">
<button class="show-code">Code</button>
bool <strong>solvePositionConstraints</strong>(num baumgarte) <a class="anchor-link" href="#solvePositionConstraints"
              title="Permalink to ConstantVolumeJoint.solvePositionConstraints">#</a></h4>
<div class="doc">
<p>Solves for the impact of this joint on the positions of the connected
bodies. Implements abstract method in <a class="crossref" href="../box2d/Joint.html">Joint</a>.</p>
<pre class="source">
bool solvePositionConstraints(num baumgarte) {
 return constrainEdges(step);
}
</pre>
</div>
</div>
<div class="method"><h4 id="solveVelocityConstraints">
<button class="show-code">Code</button>
void <strong>solveVelocityConstraints</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> argStep) <a class="anchor-link" href="#solveVelocityConstraints"
              title="Permalink to ConstantVolumeJoint.solveVelocityConstraints">#</a></h4>
<div class="doc">
<p>Solves for the impact of this joint on the velocities of the connected
bodies. Implements abstract method in <a class="crossref" href="../box2d/Joint.html">Joint</a>.</p>
<pre class="source">
void solveVelocityConstraints(TimeStep argStep) {
 num crossMassSum = 0.0;
 num dotMassSum = 0.0;

 final d = new List&lt;vec2&gt;(bodies.length);
 for (int i = 0; i &lt; bodies.length; i++) {
   d[i] = new vec2.zero();
 }

 for (int i = 0; i &lt; bodies.length; ++i) {
   final int prev = (i == 0) ? bodies.length - 1 : i - 1;
   final int next = (i == bodies.length - 1) ? 0 : i + 1;
   d[i].copyFrom(bodies[next].worldCenter);
   d[i].sub(bodies[prev].worldCenter);
   dotMassSum += d[i].length2 / bodies[i].mass;
   crossMassSum += cross(bodies[i].linearVelocity, d[i]);
 }
 num lambda = -2.0 * crossMassSum / dotMassSum;
 _impulse += lambda;
 for (int i = 0; i &lt; bodies.length; ++i) {
   bodies[i].linearVelocity.x += bodies[i].invMass * d[i].y * .5 * lambda;
   bodies[i].linearVelocity.y += bodies[i].invMass * -d[i].x * .5 * lambda;
 }
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
